package com.alex.algorithm.easy;

import java.util.Stack;

public class MinStack {

    private Stack<Integer> s1 = new Stack<Integer>();
    private Stack<Integer> s2 = new Stack<Integer>();

    public void push(Integer val) {
        s1.push(val);
        if (s2.isEmpty() || val < s2.peek()) {
            s2.push(val);
        }
    }

    public Integer pop() {
        int val = s1.pop();
        if (!s2.isEmpty() && s2.peek() == val) {
            s2.pop();
        }
        return val;
    }

    public Integer top() {
        return s1.peek();
    }

    public Integer getMin() {
        return s2.peek();
    }
}
